package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.util.TypedValue;
import android.view.View;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemMakeOverPublishMainBinding;
import com.sgb.kjwl.interfaces.PublishRecyclerClick;
import com.sgb.kjwl.model.entity.enterprise.TrademarkPublishEntity;
import com.sgb.kjwl.utils.DisplayUtil;
import com.sgb.kjwl.utils.TextSizeUtils;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * 商标转让列表-adapter
 */

public class TrademarkPublishAdapter extends BaseRecycleAdapter<TrademarkPublishEntity> {

    PublishRecyclerClick<TrademarkPublishEntity> mPublishEntityPublishRecyclerClick;

    public void setmPublishEntityPublishRecyclerClick(PublishRecyclerClick<TrademarkPublishEntity> mPublishEntityPublishRecyclerClick) {
        this.mPublishEntityPublishRecyclerClick = mPublishEntityPublishRecyclerClick;
    }

    public TrademarkPublishAdapter(Context context, List<TrademarkPublishEntity> datas) {
        super(context, R.layout.item_make_over_publish_main, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, TrademarkPublishEntity talentEntity) {
        holder.setBinding(BR.entity, talentEntity);

        ItemMakeOverPublishMainBinding binding = (ItemMakeOverPublishMainBinding) holder.getmBinding();

        if (talentEntity.getName().length() == 1){
            binding.tvItemMakeOverPublishMainPicture.setTextSize(TypedValue.COMPLEX_UNIT_SP,22);
        }else {
            binding.tvItemMakeOverPublishMainPicture.setTextSize(TypedValue.COMPLEX_UNIT_SP,(Math.max((20 - 2 * (talentEntity.getName().length() / 2)), 10)));
        }

        if (talentEntity.getColor() == null && talentEntity.getImg() == null){
            binding.ivItemMakeOverPublishMainPictureImg.setVisibility(View.GONE);
            binding.tvItemMakeOverPublishMainPicture.setVisibility(View.VISIBLE);
            binding.tvItemMakeOverPublishMainPicture.setText(TextSizeUtils.singleTextLine(DisplayUtil.dip2px(context,80),binding.tvItemMakeOverPublishMainPicture.getTextSize(),talentEntity.getName()));
        }else {
            binding.ivItemMakeOverPublishMainPictureImg.setVisibility(View.VISIBLE);
            binding.tvItemMakeOverPublishMainPicture.setVisibility(View.GONE);
        }
        holder.getItem().findViewById(R.id.tv_item_make_over_publish_main_up_and_down).setOnClickListener(v -> mPublishEntityPublishRecyclerClick.recyclerClick(talentEntity));

        if (null==talentEntity.getOrderStatus()||"3".equals(talentEntity.getOrderStatus())){
            binding.tvItemMakeOverPublishMainUpAndDown.setVisibility(View.VISIBLE);
            binding.imgSbStatus.setImageDrawable(context.getResources().getDrawable(R.mipmap.icon_zai_shou_zhong));
        }else if("1".equals(talentEntity.getOrderStatus())||"2".equals(talentEntity.getOrderStatus())||"4".equals(talentEntity.getOrderStatus())){
            binding.tvItemMakeOverPublishMainUpAndDown.setVisibility(View.GONE);
            binding.imgSbStatus.setImageDrawable(context.getResources().getDrawable(R.mipmap.icon_jiaoyizhong));
        }else if ("5".equals(talentEntity.getOrderStatus())){
            binding.tvItemMakeOverPublishMainUpAndDown.setVisibility(View.GONE);
            binding.imgSbStatus.setImageDrawable(context.getResources().getDrawable(R.mipmap.icon_yichushou));
        }
    }
}
